#include <opencv2/core/hal/interface.h>
#include <iostream>
#include <opencv2/core/matx.hpp>
#include <opencv2/core/types.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include "example.h"

int main()
{
    cv::Mat image = cv::imread("../picture/dog.jpg");
    cv::Mat gray = cv::imread("../picture/dog.jpg", cv::IMREAD_GRAYSCALE);
    //访问以下坐标点的像素值

    std::ofstream outfile("out.txt");


    //cv::Point2i point1(90, 25);
    cv::Vec3b pixel = image.at<cv::Vec3b>(90, 25);
    int grayscaled_value = (int)gray.at<uchar>(90, 25);
    std::cout << "Pixel value at (90, 25): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << std::endl;
    std::cout << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile << "Pixel value at (90, 25): " << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << std::endl;
    outfile << "Grayscaled value: " << grayscaled_value << std::endl;
    //cv::Point2i point2(152, 96);
    pixel = image.at<cv::Vec3b>(152, 96);
    grayscaled_value = (int)gray.at<uchar>(152, 96);
    std::cout << "Pixel value at (152, 96): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << std::endl;
    std::cout << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile << "Pixel value at (152, 96): " << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << std::endl;
    outfile << "Grayscaled value: " << grayscaled_value << std::endl;
    //cv::Point2i point3(561, 36);
    pixel = image.at<cv::Vec3b>(561, 36);
    grayscaled_value = (int)gray.at<uchar>(561,36);
    std::cout << "Pixel value at (561, 36): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << std::endl;
    std::cout << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile << "Pixel value at (561, 36): " << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << std::endl;
    outfile << "Grayscaled value: " << grayscaled_value << std::endl;
    //cv::Point2i point4(326, 514);
    pixel = image.at<cv::Vec3b>(326, 514);
    grayscaled_value = (int)gray.at<uchar>(326, 514);
    std::cout << "Pixel value at (326, 514): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << std::endl;
    std::cout << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile << "Pixel value at (326, 514): " << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << std::endl;
    outfile << "Grayscaled value: " << grayscaled_value << std::endl;
    //cv::Point2i point5(422, 46);
    pixel = image.at<cv::Vec3b>(422, 46);
    grayscaled_value = (int)gray.at<uchar>(422, 46);
    std::cout << "Pixel value at (422, 46): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << std::endl;
    std::cout << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile << "Pixel value at (422, 46): " << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << std::endl;
    outfile << "Grayscaled value: " << grayscaled_value << std::endl;
    outfile.close();

    cv::namedWindow("演示输出图像", cv::WINDOW_NORMAL);
    cv::imshow("演示输出图像", image);
    cv::waitKey(0);
    cv::imshow("灰度输出图像", gray);
    //如果不加waitkey,显示窗口一闪而过就结束了
    cv::waitKey(0);


}
